<template>
    <div class="Top_box">
        <ul class="subbox_top" ref="subbox_top">
            <li v-for="(item, index) in btns" :key="index">
                <span @click="HandClick(item)">{{ item.name }}</span>
            </li>
        </ul>
        <i class="el-icon-close" @click="HandClick('back')"></i>
    </div>
</template>
<script>
import { Add, Upd } from '@/api/index';
export default {
    props: ['fom', 'tabList'],
    name: 'subboxTop',
    data() {
        return {
            //按钮组
            btns: [
                { name: '保存', clickBtn: 'sav' },
                { name: '审核', clickBtn: 'aud' },
                // { name: 'xx', clickBtn: 'del' },
                { name: '下推', clickBtn: 'psD' }
                // { name: 'xx', clickBtn: 'fil' }
            ],
            param: {}
        };
    },
    methods: {
        //按钮组的方法
        HandClick(item) {
            let allList = JSON.parse(sessionStorage.getItem('tableHeaddataparam'));
            switch (item.clickBtn || item) {
                case 'sav':
                    if (this.$route.query.name != 'Upd') {
                        if (allList.existEntity == false) {
                            (this.param.entityIdentifications = []),
                                (this.param.entityRecords = {}),
                                (this.param.headIdentification = allList.tabIdentification),
                                (this.param.headRecord = this.fom),
                                (this.param.pid = ''),
                                (this.param.tableId = allList.tabId);
                        } else {
                            (this.param.entityIdentifications = []),
                                (this.param.entityRecords = {}),
                                (this.param.headIdentification = allList.tabIdentification),
                                (this.param.headRecord = this.fom),
                                (this.param.pid = ''),
                                (this.param.tableId = allList.tabId);
                        }
                        Add(this.param).then(({ data }) => {
                            console.log(this.param);
                            console.log(data);
                            if (data.code == 0) {
                                this.$message({
                                    message: data.msg,
                                    type: 'success'
                                });
                            }
                        });
                    } else {
                        if (allList.existEntity == false) {
                            (this.param.entityIdentifications = []),
                                (this.param.entityRecords = {}),
                                (this.param.headIdentification = allList.tabIdentification),
                                (this.param.headRecord = this.fom),
                                (this.param.tableId = allList.tabId);
                        }

                        Upd(this.param).then(({ data }) => {
                            if (data.code == 0) {
                                this.$message({
                                    message: data.msg,
                                    type: 'success'
                                });
                            }
                        });
                    }

                    break;
                case 'aud':
                    console.log('审核');
                    break;
                case 'del':
                    break;
                case 'psD':
                    console.log('下推');
                    break;

                case 'back':
                    this.$router.back();
                    break;
                default:
                    break;
            }
        }
    }
};
</script>

<style lang="less" scoped>
.Top_box {
    width: 100%;
    display: flex;
    justify-content: space-between;
    padding: 0 15px;
    box-sizing: border-box;
    .subbox_top {
        width: 100%;
        line-height: 30px;
        display: flex;
        margin-bottom: 15px;
        li {
            width: 80px;
            line-height: 27px;
            cursor: pointer;
            span {
                background: linear-gradient(to right, #4672f8, #6f6ffa);
                color: #fff;
                padding: 5px 15px;
                box-sizing: border-box;
                border-radius: 13.5px;
            }
        }
    }
    i {
        font-size: 25px;
        cursor: pointer;
    }
}
</style>